<?php
header("Content-Type:text/html;charset=utf-8");

 
$p	= null;
$p	= new newpost();
global $HTTP_RAW_POST_DATA;
$res = $HTTP_RAW_POST_DATA;
$res=trim($res);
$res=rawurldecode($res);



	$xml_parser = new XML();
	$data = $xml_parser->parse($res);
	$xml_parser->destruct();
	
	$ExternalId = $data[XML][USER][EXTERNALID];
	$Sender = $data[XML][USER][SENDER];
	$Message = $data[XML][USER][MESSAGE];
	$systemid = $data[XML][SYSTEM][SYSTEMID];
	$type = $data[XML][SYSTEM][TYPE];
	if ($type=="qq" or $type==""){
if($p->yz($ExternalId,$Sender,$Message))
	{


if( $ExternalId == "0")
		{
			
			$r = $db2->query('SELECT id FROM applications WHERE name="QQ" LIMIT 1');
		
		while($obj = $db2->fetch_object($r)) {
			
			$apiid=$obj->id;
			
			}
			
		}
		else 
		{
			$r = $db2->query('SELECT id FROM applications WHERE name="QQ签名" LIMIT 1');
		
		while($obj = $db2->fetch_object($r)) {
			
			$apiid=$obj->id;
			
			}
		}
	$r = $db2->query('SELECT uid FROM cdb_qq WHERE qq="'.$Sender.'" ');
		
		while($obj = $db2->fetch_object($r)) {
			
			$uid=$obj->uid;
			
			}
	
		
		$p->set_api_id($apiid);
		$p->set_message($Message);
		$tmpu = $network->get_user_by_id($uid);
		$tmpu->info	= $tmpu;
		$tmpu->is_logged	= TRUE;
		$p->set_user_advanced( $network,  $tmpu );
		$res = $p->save();
		if(  $res ) {

			echo("ok");

			}	

		else 
			{
				echo("wrong");
			}
			
}
}
else{
if ($type=="sms"){
	$r = $db2->query('SELECT id FROM applications WHERE name="短信" LIMIT 1');
		
		while($obj = $db2->fetch_object($r)) {
			
			$apiid=$obj->id;
			
			}
	$r = $db2->query('SELECT id FROM users WHERE tel="'.$Sender.'" ');
		
		while($obj = $db2->fetch_object($r)) {
			
			$uid=$obj->id;
			
			}	
				$p->set_api_id($apiid);
		$p->set_message($Message);
		$tmpu = $network->get_user_by_id($uid);
		$tmpu->info	= $tmpu;
		$tmpu->is_logged	= TRUE;
		$p->set_user_advanced( $network,  $tmpu );
		$res = $p->save();
		if(  $res ) {

			echo("ok");

			}	

		else 
			{
				echo("wrong");
			}
	
}
}
?>
